
"use strict";
/* Controllers */
app.controller("dataMetricListController", ['$scope', '$location', '$rootScope', '$routeParams', 'dataMetricListService', function ($scope, $location, $rootScope, $routeParams, dataMetricListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listMetric = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = {};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        dataMetricListService.listMetric(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [10, 30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listMetric();


        $resultTable.bootstrapTable('hideColumn', 'ownerID');
        $resultTable.bootstrapTable('hideColumn', 'dataMetricType');
        $resultTable.bootstrapTable('hideColumn', 'dataMetricTbl');
        $resultTable.bootstrapTable('hideColumn', 'dataMetricImpl');
    };

    $scope.initializeController();

}]);


/* Services */
app.service('dataMetricListService', ['ajaxService', function (ajaxService) {

    this.listMetric = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/data_metric/listMetric.do", successFunction, errorFunction);
    };
}]);

function dataMetricIDOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/dataMetric/dataMetric_add/', value,'" target="_blank">', "<u>修改</u>" , '</a>'
    ].join('');
}


